package book;

public class Book {
    private String name;
    private String author;
    private int price;
    private String type;  //图书类型
    private boolean isBorrowed; //图书是否借出

    //创建构造方法，在new时传入并初始化书的信息
    public Book(String name, String author, int price, String type) {
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
    }


    //查找等各种操作都需要输入图书名字，所以需要getName访问book的name信息
    public String getName() {
        return name;
    }


    //借阅和归还都需要设置book中的boolean值
    public void setBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }

    //打印时防止打印book对象的地址，重写object类的toString方法
    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ", isBorrowed=" + ((isBorrowed == false) ? "未借出" : "已借出") +
                '}';
    }
}


